package com.zzptc.zzsgz.baiduwsapp;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SharedPreferences sharedPreferences=getSharedPreferences("login", Context.MODE_PRIVATE);//获取共享首选项
       SharedPreferences.Editor editor= sharedPreferences.edit();//编辑器
        editor.putBoolean("log",false);
        editor.putString("username","admin");//写
        editor.putString("password","admin");
        editor.commit();//执行命令


        //读出来
        Toast.makeText(this, sharedPreferences.getString("username",null), Toast.LENGTH_SHORT).show();

    }
}
